﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Text;
using Token.Util;
using Token.Piker.DAL;
using Token.Piker.Model;

namespace Token.Piker.Core.Photo
{
    public class PhotoProxy
    {

        public static  Token.Piker.Model.Photo GetPhoto(string pid)
        {
            Token.Piker.DAL.PhotoDAL photo_accessor = new Token.Piker.DAL.PhotoDAL();
            try
            {
                var photo = photo_accessor.GetModel(Convert.ToInt32(pid));
                return photo;
            }
            catch
            {
                return null;
            }
           
        }

        public static int AddPhoto( Token.Piker.Model.Photo photo)
        {
            Token.Piker.DAL.PhotoDAL photo_accessor = new Token.Piker.DAL.PhotoDAL();
            try
            {
                return photo_accessor.Add(photo);
            }
            catch
            {
                return -1;
            }
        }

        public static int UpdateAlbumCover(Token.Piker.Model.Photo photo)
        {
            Token.Piker.DAL.AlbumDAL dal_Album = new Token.Piker.DAL.AlbumDAL();
            Token.Piker.Model.Album model = dal_Album.GetModel(Convert.ToInt32(photo.Album));
            model.CoverURL = photo.CompressUrl_1;
            try
            {
                return dal_Album.Update(model) ? 1 : -1;
            }
            catch
            {
                return -1;
            }
        }

        public static void FilterPhoto(Token.Piker.Model.Photo photo)
        {
            WebHelper.FilterJSText(photo.City);
            WebHelper.FilterJSText(photo.Descrip);
            WebHelper.FilterJSText(photo.PhotoName);
            WebHelper.FilterJSText(photo.Position);
            WebHelper.FilterJSText(photo.Province);
        }

        public static int AddPhotoTag(string pid, string tid)
        {
            PhotoTagDAL dao = new PhotoTagDAL();
            PhotoTag model = new PhotoTag();
            model.PID = Convert.ToInt32(pid);
            model.TID = Convert.ToInt32(tid);
            return dao.Add(model);
        }

        /// <summary>
        /// 是否被用户喜欢过
        /// </summary>
        /// <param name="uid"></param>
        /// <param name="pid"></param>
        /// <returns></returns>
        public static bool IsLikedByUser(string uid, string pid)
        {
            //待写完
            return false;
        }


        /// <summary>
        /// 添加Photo的喜欢信息
        /// </summary>
        /// <param name="uid"></param>
        /// <param name="pid"></param>
        /// <returns></returns>
        public static bool AddLikeInfo(string uid, string pid)
        {
            //待写完
            return true;
        }


        public static DataSet GetPhotoList(string where)
        {
            try
            {
                Token.Piker.DAL.PhotoDAL photo_accessor = new Token.Piker.DAL.PhotoDAL();  //实例化类
                DataSet ds = photo_accessor.GetList(where);  //获取数据 where 是sql的查询条件
                return ds;
            }
            catch (System.Exception ex)
            {
                return null;
            }
            
        }

    }
}
